package com.wk.worksetter.adapter

import android.content.pm.PackageInfo
import android.graphics.drawable.Drawable
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.wk.worksetter.R
import com.wk.worksetter.utils.WorkUtil

/**
 * @author peng
 * @date 2021/1/28
 * 说明
 */
class AppInfoAdapter(
    packageInfos: List<PackageInfo>?,
    private val appIconWithPackage: MutableMap<String, Drawable?>?
) : BaseQuickAdapter<PackageInfo,BaseViewHolder>(R.layout.item_packageinfo,packageInfos?.toMutableList()) {
    override fun convert(holder: BaseViewHolder, item: PackageInfo) {
        holder.setText(R.id.tv_app_name,WorkUtil.getAppLabelName(item))
        holder.setText(R.id.tv_app_version_name,item.versionName)
        holder.setImageDrawable(R.id.iv_app_icon,(appIconWithPackage?.get(item.packageName))?:WorkUtil.getAppIcon(item))
    }
}